﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Sun.Mvc.Framework
{
    public class Salt
    {
        private readonly static string salt = Guid.NewGuid().ToString();

        /// <summary>
        /// 混淆密码
        /// </summary>
        /// <param name="Password">密码</param>
        /// <returns>返回Salt、NewPassword</returns>
        public static Tuple<string,string> HashSalt(string Password)
        {
            byte[] passwordAndSaltBytes = System.Text.Encoding.UTF8.GetBytes(Password + salt);
            byte[] hashBytes = new System.Security.Cryptography.SHA256Managed().ComputeHash(passwordAndSaltBytes);


            return Tuple.Create(salt,Convert.ToBase64String(hashBytes));
        }

        /// <summary>
        /// 混淆密码
        /// </summary>
        /// <param name="Password">密码</param>
        /// <returns>返回Salt</returns>
        public static string HashSalt(string Password, string Salt)
        {
            byte[] passwordAndSaltBytes = System.Text.Encoding.UTF8.GetBytes(Password + Salt);
            byte[] hashBytes = new System.Security.Cryptography.SHA256Managed().ComputeHash(passwordAndSaltBytes);

            return Convert.ToBase64String(hashBytes);
        }

        public static string Sha1(string Password)
        {
            SHA1 a1= SHA1.Create(Password);
            SHA1 sha1 =new SHA1CryptoServiceProvider();

            return "";
        }
    }
}
